package com.example.maze;

import android.os.Parcel;
import android.os.Parcelable;

public class Position implements Parcelable {
	// gets and stores a position

	private final int x;

	private final int y;

	public Position(int x, int y) {
		this.x = x;
		this.y = y;
	}

	public int getX() {
		return x;
	}

	public int getY() {
		return y;
	}

	// a hashCode and an equals method as the given equals method cannot be
	// trusted

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + x;
		result = prime * result + y;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Position other = (Position) obj;
		if (x != other.x)
			return false;
		if (y != other.y)
			return false;
		return true;
	}

	//making a parcel out of this object and rebuilding this object from a parcel
	
	//doesnt matter
	@Override
	public int describeContents() {
		return 0;
	}

	@Override
	public void writeToParcel(Parcel dest, int flags) {
		dest.writeInt(x);
		dest.writeInt(y);
	}

	public static final Parcelable.Creator<Position> CREATOR = new Parcelable.Creator<Position>() {
		
		public Position createFromParcel(Parcel in) {
			return new Position(in);
		}

		@Override
		public Position[] newArray(int size) {
			return new Position[size];
		}
	};

	private Position(Parcel in) {
		this.x = in.readInt();
		this.y = in.readInt();
	}

}
